﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using TyMES.Model.BaseInformation;
using TyMES.Model;

namespace TyMES.ViewModel.BaseInformation.ProductBOMVMs
{
    public partial class ProductBOMListVM : BasePagedListVM<ProductBOM_View, ProductBOMSearcher>
    {
        
        protected override IEnumerable<IGridColumn<ProductBOM_View>> InitGridHeader()
        {
            return new List<GridColumn<ProductBOM_View>>{
                
                this.MakeGridHeader(x => x.ProductBOM_factoryCode).SetTitle(@Localizer["Page.工厂编码"].Value),
                this.MakeGridHeader(x => x.ProductBOM_assemblyline).SetTitle(@Localizer["Page.装配产线"].Value),
                this.MakeGridHeader(x => x.ProductBOM_operationCode).SetTitle(@Localizer["Page.工序编码"].Value),
                this.MakeGridHeader(x => x.ProductBOM_orderCode).SetTitle(@Localizer["Page.工单编码"].Value),
                this.MakeGridHeader(x => x.ProductBOM_scheduleNumber).SetTitle(@Localizer["Page.排程号"].Value),
                this.MakeGridHeader(x => x.ProductBOM_addTime).SetTitle(@Localizer["Page.添加时间"].Value),
                this.MakeGridHeader(x => x.ProductBOM_assemblyConsumption).SetTitle(@Localizer["Page.组件物料数量"].Value),
                this.MakeGridHeader(x => x.ProductBOM_assemblyMaterialCode).SetTitle(@Localizer["Page.组件物料编码"].Value),
                this.MakeGridHeader(x => x.ProductBOM_assemblyMaterialId).SetTitle(@Localizer["Page.组件物料Id"].Value),
                this.MakeGridHeader(x => x.ProductBOM_assemblyMaterialName).SetTitle(@Localizer["Page.组件物料名称"].Value),
                this.MakeGridHeader(x => x.ProductBOM_assemblyMaterialRegex).SetTitle(@Localizer["Page.组件物料正则规则"].Value),
                this.MakeGridHeader(x => x.ProductBOM_assemblyMaterialVersion).SetTitle(@Localizer["Page.组件物料版本"].Value),
                this.MakeGridHeader(x => x.ProductBOM_assemblyUnitCode).SetTitle(@Localizer["Page.组件物料单位编码"].Value),
                this.MakeGridHeader(x => x.ProductBOM_autoMaterialDeduction).SetTitle(@Localizer["Page.装配扣除额"].Value),
                this.MakeGridHeader(x => x.ProductBOM_editTime).SetTitle(@Localizer["Page.编辑时间"].Value),
                this.MakeGridHeader(x => x.ProductBOM_field1).SetTitle(@Localizer["Page.备用字段1"].Value),
                this.MakeGridHeader(x => x.ProductBOM_field2).SetTitle(@Localizer["Page.备用字段2"].Value),
                this.MakeGridHeader(x => x.ProductBOM_field3).SetTitle(@Localizer["Page.备用字段3"].Value),
                this.MakeGridHeader(x => x.ProductBOM_field4).SetTitle(@Localizer["Page.备用字段4"].Value),
                this.MakeGridHeader(x => x.ProductBOM_field5).SetTitle(@Localizer["Page.备用字段5"].Value),
                this.MakeGridHeader(x => x.ProductBOM_isDelete).SetTitle(@Localizer["Page.是否删除"].Value),
                this.MakeGridHeader(x => x.ProductBOM_materialCode).SetTitle(@Localizer["Page.物料编码"].Value),
                this.MakeGridHeader(x => x.ProductBOM_materialId).SetTitle(@Localizer["Page.物料Id"].Value),
                this.MakeGridHeader(x => x.ProductBOM_materialName).SetTitle(@Localizer["Page.物料名称"].Value),
                this.MakeGridHeader(x => x.ProductBOM_materialRegex).SetTitle(@Localizer["Page.物料正则"].Value),
                this.MakeGridHeader(x => x.ProductBOM_materialSort).SetTitle(@Localizer["Page.物料排序"].Value),
                this.MakeGridHeader(x => x.ProductBOM_materialVersion).SetTitle(@Localizer["Page.物料版本"].Value),
                this.MakeGridHeader(x => x.ProductBOM_orderId).SetTitle(@Localizer["Page.工单Id"].Value),
                this.MakeGridHeader(x => x.ProductBOM_orderQty).SetTitle(@Localizer["Page.工单数量"].Value),
                this.MakeGridHeader(x => x.ProductBOM_productBomId).SetTitle(@Localizer["Page.产品BOM编号"].Value),
                this.MakeGridHeader(x => x.ProductBOM_replaceMaterialList).SetTitle(@Localizer["Page.替换物料表"].Value),
                this.MakeGridHeader(x => x.ProductBOM_replaces).SetTitle(@Localizer["Page.替换用量"].Value),
                this.MakeGridHeader(x => x.ProductBOM_retroactive).SetTitle(@Localizer["Page.追溯方式"].Value),
                this.MakeGridHeader(x => x.ProductBOM_routeBomCode).SetTitle(@Localizer["Page.工艺BOM编码"].Value),
                this.MakeGridHeader(x => x.ProductBOM_routeBomName).SetTitle(@Localizer["Page.工艺BOM名称"].Value),
                this.MakeGridHeader(x => x.ProductBOM_routeNumber).SetTitle(@Localizer["Page.工艺路线编码"].Value),
                this.MakeGridHeader(x => x.ProductBOM_shipRegularCheck).SetTitle(@Localizer["Page.出货规则校验"].Value),
                this.MakeGridHeader(x => x.ProductBOM_shopOrderOperationMaterialId).SetTitle(@Localizer["Page.工单工序物料关联id"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<ProductBOM_View> GetSearchQuery()
        {
            var query = DC.Set<ProductBOM>()
                
                .CheckContain(Searcher.FactoryCode, x=>x.FactoryCode)
                .CheckContain(Searcher.Assemblyline, x=>x.Assemblyline)
                .CheckContain(Searcher.OperationCode, x=>x.OperationCode)
                .CheckContain(Searcher.OrderCode, x=>x.OrderCode)
                .CheckContain(Searcher.ScheduleNumber, x=>x.ScheduleNumber)
                .CheckContain(Searcher.AddTime, x=>x.AddTime)
                .CheckContain(Searcher.AssemblyConsumption, x=>x.AssemblyConsumption)
                .CheckContain(Searcher.AssemblyMaterialCode, x=>x.AssemblyMaterialCode)
                .CheckContain(Searcher.AssemblyMaterialId, x=>x.AssemblyMaterialId)
                .CheckContain(Searcher.AssemblyMaterialName, x=>x.AssemblyMaterialName)
                .CheckContain(Searcher.AssemblyMaterialRegex, x=>x.AssemblyMaterialRegex)
                .CheckContain(Searcher.AssemblyMaterialVersion, x=>x.AssemblyMaterialVersion)
                .CheckContain(Searcher.AssemblyUnitCode, x=>x.AssemblyUnitCode)
                .CheckEqual(Searcher.AutoMaterialDeduction, x=>x.AutoMaterialDeduction)
                .CheckContain(Searcher.EditTime, x=>x.EditTime)
                .CheckContain(Searcher.Field1, x=>x.Field1)
                .CheckContain(Searcher.Field2, x=>x.Field2)
                .CheckContain(Searcher.Field3, x=>x.Field3)
                .CheckContain(Searcher.Field4, x=>x.Field4)
                .CheckContain(Searcher.Field5, x=>x.Field5)
                .CheckContain(Searcher.IsDelete, x=>x.IsDelete)
                .CheckContain(Searcher.MaterialCode, x=>x.MaterialCode)
                .CheckContain(Searcher.MaterialId, x=>x.MaterialId)
                .CheckContain(Searcher.MaterialName, x=>x.MaterialName)
                .CheckContain(Searcher.MaterialRegex, x=>x.MaterialRegex)
                .CheckContain(Searcher.MaterialSort, x=>x.MaterialSort)
                .CheckContain(Searcher.MaterialVersion, x=>x.MaterialVersion)
                .CheckContain(Searcher.OrderId, x=>x.OrderId)
                .CheckContain(Searcher.OrderQty, x=>x.OrderQty)
                .CheckContain(Searcher.ProductBomId, x=>x.ProductBomId)
                .CheckContain(Searcher.ReplaceMaterialList, x=>x.ReplaceMaterialList)
                .CheckEqual(Searcher.Replaces, x=>x.Replaces)
                .CheckContain(Searcher.Retroactive, x=>x.Retroactive)
                .CheckContain(Searcher.RouteBomCode, x=>x.RouteBomCode)
                .CheckContain(Searcher.RouteBomName, x=>x.RouteBomName)
                .CheckContain(Searcher.RouteNumber, x=>x.RouteNumber)
                .CheckContain(Searcher.ShipRegularCheck, x=>x.ShipRegularCheck)
                .CheckContain(Searcher.ShopOrderOperationMaterialId, x=>x.ShopOrderOperationMaterialId)
                .Select(x => new ProductBOM_View
                {
				    ID = x.ID,
                    
                    ProductBOM_factoryCode = x.FactoryCode,
                    ProductBOM_assemblyline = x.Assemblyline,
                    ProductBOM_operationCode = x.OperationCode,
                    ProductBOM_orderCode = x.OrderCode,
                    ProductBOM_scheduleNumber = x.ScheduleNumber,
                    ProductBOM_addTime = x.AddTime,
                    ProductBOM_assemblyConsumption = x.AssemblyConsumption,
                    ProductBOM_assemblyMaterialCode = x.AssemblyMaterialCode,
                    ProductBOM_assemblyMaterialId = x.AssemblyMaterialId,
                    ProductBOM_assemblyMaterialName = x.AssemblyMaterialName,
                    ProductBOM_assemblyMaterialRegex = x.AssemblyMaterialRegex,
                    ProductBOM_assemblyMaterialVersion = x.AssemblyMaterialVersion,
                    ProductBOM_assemblyUnitCode = x.AssemblyUnitCode,
                    ProductBOM_autoMaterialDeduction = x.AutoMaterialDeduction,
                    ProductBOM_editTime = x.EditTime,
                    ProductBOM_field1 = x.Field1,
                    ProductBOM_field2 = x.Field2,
                    ProductBOM_field3 = x.Field3,
                    ProductBOM_field4 = x.Field4,
                    ProductBOM_field5 = x.Field5,
                    ProductBOM_isDelete = x.IsDelete,
                    ProductBOM_materialCode = x.MaterialCode,
                    ProductBOM_materialId = x.MaterialId,
                    ProductBOM_materialName = x.MaterialName,
                    ProductBOM_materialRegex = x.MaterialRegex,
                    ProductBOM_materialSort = x.MaterialSort,
                    ProductBOM_materialVersion = x.MaterialVersion,
                    ProductBOM_orderId = x.OrderId,
                    ProductBOM_orderQty = x.OrderQty,
                    ProductBOM_productBomId = x.ProductBomId,
                    ProductBOM_replaceMaterialList = x.ReplaceMaterialList,
                    ProductBOM_replaces = x.Replaces,
                    ProductBOM_retroactive = x.Retroactive,
                    ProductBOM_routeBomCode = x.RouteBomCode,
                    ProductBOM_routeBomName = x.RouteBomName,
                    ProductBOM_routeNumber = x.RouteNumber,
                    ProductBOM_shipRegularCheck = x.ShipRegularCheck,
                    ProductBOM_shopOrderOperationMaterialId = x.ShopOrderOperationMaterialId,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class ProductBOM_View: ProductBOM
    {
        
        public string ProductBOM_factoryCode { get; set; }
        public string ProductBOM_assemblyline { get; set; }
        public string ProductBOM_operationCode { get; set; }
        public string ProductBOM_orderCode { get; set; }
        public string ProductBOM_scheduleNumber { get; set; }
        public string ProductBOM_addTime { get; set; }
        public string ProductBOM_assemblyConsumption { get; set; }
        public string ProductBOM_assemblyMaterialCode { get; set; }
        public string ProductBOM_assemblyMaterialId { get; set; }
        public string ProductBOM_assemblyMaterialName { get; set; }
        public string ProductBOM_assemblyMaterialRegex { get; set; }
        public string ProductBOM_assemblyMaterialVersion { get; set; }
        public string ProductBOM_assemblyUnitCode { get; set; }
        public int? ProductBOM_autoMaterialDeduction { get; set; }
        public string ProductBOM_editTime { get; set; }
        public string ProductBOM_field1 { get; set; }
        public string ProductBOM_field2 { get; set; }
        public string ProductBOM_field3 { get; set; }
        public string ProductBOM_field4 { get; set; }
        public string ProductBOM_field5 { get; set; }
        public string ProductBOM_isDelete { get; set; }
        public string ProductBOM_materialCode { get; set; }
        public string ProductBOM_materialId { get; set; }
        public string ProductBOM_materialName { get; set; }
        public string ProductBOM_materialRegex { get; set; }
        public string ProductBOM_materialSort { get; set; }
        public string ProductBOM_materialVersion { get; set; }
        public string ProductBOM_orderId { get; set; }
        public string ProductBOM_orderQty { get; set; }
        public string ProductBOM_productBomId { get; set; }
        public string ProductBOM_replaceMaterialList { get; set; }
        public int? ProductBOM_replaces { get; set; }
        public string ProductBOM_retroactive { get; set; }
        public string ProductBOM_routeBomCode { get; set; }
        public string ProductBOM_routeBomName { get; set; }
        public string ProductBOM_routeNumber { get; set; }
        public string ProductBOM_shipRegularCheck { get; set; }
        public string ProductBOM_shopOrderOperationMaterialId { get; set; }

    }

}